// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Serverless.Fluent;
using Elastic.Clients.Elasticsearch.Serverless.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.Serverless.TransformManagement;

/// <summary>
/// <para>The source of the data for the transform.</para>
/// </summary>
public sealed partial class Settings
{
	/// <summary>
	/// <para>Specifies whether the transform checkpoint ranges should be optimized for performance. Such optimization can align<br/>checkpoint ranges with the date histogram interval when date histogram is specified as a group source in the<br/>transform config. As a result, less document updates in the destination index will be performed thus improving<br/>overall performance.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("align_checkpoints")]
	public bool? AlignCheckpoints { get; set; }

	/// <summary>
	/// <para>Defines if dates in the ouput should be written as ISO formatted string or as millis since epoch. epoch_millis was<br/>the default for transforms created before version 7.11. For compatible output set this value to `true`.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("dates_as_epoch_millis")]
	public bool? DatesAsEpochMillis { get; set; }

	/// <summary>
	/// <para>Specifies whether the transform should deduce the destination index mappings from the transform configuration.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("deduce_mappings")]
	public bool? DeduceMappings { get; set; }

	/// <summary>
	/// <para>Specifies a limit on the number of input documents per second. This setting throttles the transform by adding a<br/>wait time between search requests. The default value is null, which disables throttling.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("docs_per_second")]
	public float? DocsPerSecond { get; set; }

	/// <summary>
	/// <para>Defines the initial page size to use for the composite aggregation for each checkpoint. If circuit breaker<br/>exceptions occur, the page size is dynamically adjusted to a lower value. The minimum value is `10` and the<br/>maximum is `65,536`.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("max_page_search_size")]
	public int? MaxPageSearchSize { get; set; }

	/// <summary>
	/// <para>If `true`, the transform runs in unattended mode. In unattended mode, the transform retries indefinitely in case<br/>of an error which means the transform never fails. Setting the number of retries other than infinite fails in<br/>validation.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("unattended")]
	public bool? Unattended { get; set; }
}

/// <summary>
/// <para>The source of the data for the transform.</para>
/// </summary>
public sealed partial class SettingsDescriptor : SerializableDescriptor<SettingsDescriptor>
{
	internal SettingsDescriptor(Action<SettingsDescriptor> configure) => configure.Invoke(this);

	public SettingsDescriptor() : base()
	{
	}

	private bool? AlignCheckpointsValue { get; set; }
	private bool? DatesAsEpochMillisValue { get; set; }
	private bool? DeduceMappingsValue { get; set; }
	private float? DocsPerSecondValue { get; set; }
	private int? MaxPageSearchSizeValue { get; set; }
	private bool? UnattendedValue { get; set; }

	/// <summary>
	/// <para>Specifies whether the transform checkpoint ranges should be optimized for performance. Such optimization can align<br/>checkpoint ranges with the date histogram interval when date histogram is specified as a group source in the<br/>transform config. As a result, less document updates in the destination index will be performed thus improving<br/>overall performance.</para>
	/// </summary>
	public SettingsDescriptor AlignCheckpoints(bool? alignCheckpoints = true)
	{
		AlignCheckpointsValue = alignCheckpoints;
		return Self;
	}

	/// <summary>
	/// <para>Defines if dates in the ouput should be written as ISO formatted string or as millis since epoch. epoch_millis was<br/>the default for transforms created before version 7.11. For compatible output set this value to `true`.</para>
	/// </summary>
	public SettingsDescriptor DatesAsEpochMillis(bool? datesAsEpochMillis = true)
	{
		DatesAsEpochMillisValue = datesAsEpochMillis;
		return Self;
	}

	/// <summary>
	/// <para>Specifies whether the transform should deduce the destination index mappings from the transform configuration.</para>
	/// </summary>
	public SettingsDescriptor DeduceMappings(bool? deduceMappings = true)
	{
		DeduceMappingsValue = deduceMappings;
		return Self;
	}

	/// <summary>
	/// <para>Specifies a limit on the number of input documents per second. This setting throttles the transform by adding a<br/>wait time between search requests. The default value is null, which disables throttling.</para>
	/// </summary>
	public SettingsDescriptor DocsPerSecond(float? docsPerSecond)
	{
		DocsPerSecondValue = docsPerSecond;
		return Self;
	}

	/// <summary>
	/// <para>Defines the initial page size to use for the composite aggregation for each checkpoint. If circuit breaker<br/>exceptions occur, the page size is dynamically adjusted to a lower value. The minimum value is `10` and the<br/>maximum is `65,536`.</para>
	/// </summary>
	public SettingsDescriptor MaxPageSearchSize(int? maxPageSearchSize)
	{
		MaxPageSearchSizeValue = maxPageSearchSize;
		return Self;
	}

	/// <summary>
	/// <para>If `true`, the transform runs in unattended mode. In unattended mode, the transform retries indefinitely in case<br/>of an error which means the transform never fails. Setting the number of retries other than infinite fails in<br/>validation.</para>
	/// </summary>
	public SettingsDescriptor Unattended(bool? unattended = true)
	{
		UnattendedValue = unattended;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (AlignCheckpointsValue.HasValue)
		{
			writer.WritePropertyName("align_checkpoints");
			writer.WriteBooleanValue(AlignCheckpointsValue.Value);
		}

		if (DatesAsEpochMillisValue.HasValue)
		{
			writer.WritePropertyName("dates_as_epoch_millis");
			writer.WriteBooleanValue(DatesAsEpochMillisValue.Value);
		}

		if (DeduceMappingsValue.HasValue)
		{
			writer.WritePropertyName("deduce_mappings");
			writer.WriteBooleanValue(DeduceMappingsValue.Value);
		}

		if (DocsPerSecondValue.HasValue)
		{
			writer.WritePropertyName("docs_per_second");
			writer.WriteNumberValue(DocsPerSecondValue.Value);
		}

		if (MaxPageSearchSizeValue.HasValue)
		{
			writer.WritePropertyName("max_page_search_size");
			writer.WriteNumberValue(MaxPageSearchSizeValue.Value);
		}

		if (UnattendedValue.HasValue)
		{
			writer.WritePropertyName("unattended");
			writer.WriteBooleanValue(UnattendedValue.Value);
		}

		writer.WriteEndObject();
	}
}